package io.adrainty.framework.job.basic;

import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.handler.IJobHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;

/**
 * <p>AbstractXxlJobExecutor</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description AbstractXxlJobExecutor
 * @since 2025/7/22 11:00:28
 */

@Slf4j
public abstract class AbstractXxlJobExecutor<T> extends IJobHandler implements InitializingBean {

    @Override
    public void execute() {
        try {
            doExecute();
        } catch (Exception e) {
            log.error("Job execute error: ", e);
            throw e;
        }
    }

    /**
     * <p>doExecute</p>
     */
    protected abstract void doExecute();

    /**
     * <p>getJobClass</p>
     * @return Class<T>
     */
    protected abstract Class<T> getJobClass();

    /**
     * <p>register to xxl job</p>
     */
    @Override
    public void afterPropertiesSet() {
        XxlJobExecutor.registJobHandler(getJobClass().getSimpleName(), this);
    }
}
